/*
 * @Author: 小豪
 * @Description:
 * @Date: 2024-05-20 19:48:07
 * @LastEditTime: 2024-05-20 20:32:53
 * @FilePath: \bsct\gohub\app\requests\login_request.go
 */
package requests

import (
	"github.com/gin-gonic/gin"
	"gopkg.in/thedevsaddam/govalidator.v1"
)

type LoginByPhoneRequest struct {
	Phone    string `form:"phone,omitempty" valid:"phone"`
	Password string `valid:"password" form:"password,omitempty"`
}

// LoginByPhone 验证表单，返回长度等于零即通过
func LoginByPhone(data interface{}, c *gin.Context) map[string][]string {

	rules := govalidator.MapData{
		"phone":    []string{"required", "digits:11"},
		"password": []string{"required", "min:6"},
	}
	messages := govalidator.MapData{
		"phone": []string{
			"required:手机号为必填项，参数名称 phone",
			"digits:手机号长度必须为 11 位的数字",
		},
		"password": []string{
			"required:密码为必填项，参数名称 password",
			"min:密码长度需大于 6",
		},
	}

	errs := validate(data, rules, messages)
	// 开始验证
	return errs
}
